//
//  Content.m
//
//  Created by   on 15/10/7
//  Copyright (c) 2015 __MyCompanyName__. All rights reserved.
//

#import "ZCMainModel.h"


NSString *const kContentRank = @"rank";
NSString *const kContentLocation = @"location";
NSString *const kContentInstitutionid = @"institutionid";
NSString *const kContentCode = @"code";
NSString *const kContentMid = @"mid";
NSString *const kContentCtime = @"ctime";
NSString *const kContentBrand = @"brand";
NSString *const kContentEmoney = @"emoney";
NSString *const kContentPackageid = @"packageid";
NSString *const kContentPackagename = @"packagename";
NSString *const kContentPdname = @"pdname";
NSString *const kContentFromtype = @"fromtype";
NSString *const kContentState = @"state";
NSString *const kContentTestreportid = @"testreportid";
NSString *const kContentId = @"id";
NSString *const kContentSample = @"sample";
NSString *const kContentSamnum = @"samnum";
NSString *const kContentEtime = @"etime";
NSString *const kContentThumb = @"thumb";
NSString *const kContentPjname = @"pjname";
NSString *const kContentFirstCategory = @"first_category";
NSString *const kContentSecondCategory = @"second_category";
NSString *const kContentResult = @"result";
NSString *const kContentBtime = @"btime";
NSString *const kContentContent = @"content";
NSString *const kContentInstitution = @"institution";
NSString *const kContentFinish = @"finish";

NSString *const kContentBatch = @"batch";
NSString *const kContentTesting_date = @"testing_date";




@interface ZCMainModel ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation ZCMainModel

@synthesize rank = _rank;
@synthesize location = _location;
@synthesize institutionid = _institutionid;
@synthesize code = _code;
@synthesize mid = _mid;
@synthesize ctime = _ctime;
@synthesize brand = _brand;
@synthesize emoney = _emoney;
@synthesize packageid = _packageid;
@synthesize packagename = _packagename;
@synthesize pdname = _pdname;
@synthesize fromtype = _fromtype;
@synthesize state = _state;
@synthesize testreportid = _testreportid;
@synthesize contentIdentifier = _contentIdentifier;
@synthesize sample = _sample;
@synthesize samnum = _samnum;
@synthesize etime = _etime;
@synthesize thumb = _thumb;
@synthesize pjname = _pjname;
@synthesize firstCategory = _firstCategory;
@synthesize secondCategory = _secondCategory;
@synthesize result = _result;
@synthesize btime = _btime;
@synthesize content = _content;
@synthesize institution = _institution;
@synthesize finish = _finish;

@synthesize batch = _batch;
@synthesize testing_date = _testing_date;


+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{

    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict
{
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    
    if(self && [dict isKindOfClass:[NSDictionary class]]) {

            self.rank = [self objectOrNilForKey:kContentRank fromDictionary:dict];
            self.location = [self objectOrNilForKey:kContentLocation fromDictionary:dict];
            self.institutionid = [self objectOrNilForKey:kContentInstitutionid fromDictionary:dict];
            self.code = [self objectOrNilForKey:kContentCode fromDictionary:dict];
            self.mid = [self objectOrNilForKey:kContentMid fromDictionary:dict];
            self.ctime = [self objectOrNilForKey:kContentCtime fromDictionary:dict];
            self.brand = [self objectOrNilForKey:kContentBrand fromDictionary:dict];
            self.emoney = [self objectOrNilForKey:kContentEmoney fromDictionary:dict];
            self.packageid = [self objectOrNilForKey:kContentPackageid fromDictionary:dict];
            self.packagename = [self objectOrNilForKey:kContentPackagename fromDictionary:dict];
            self.pdname = [self objectOrNilForKey:kContentPdname fromDictionary:dict];
            self.fromtype = [self objectOrNilForKey:kContentFromtype fromDictionary:dict];
            self.state = [self objectOrNilForKey:kContentState fromDictionary:dict];
            self.testreportid = [self objectOrNilForKey:kContentTestreportid fromDictionary:dict];
            self.contentIdentifier = [self objectOrNilForKey:kContentId fromDictionary:dict];
            self.sample = [self objectOrNilForKey:kContentSample fromDictionary:dict];
            self.samnum = [self objectOrNilForKey:kContentSamnum fromDictionary:dict];
            self.etime = [self objectOrNilForKey:kContentEtime fromDictionary:dict];
            self.thumb = [self objectOrNilForKey:kContentThumb fromDictionary:dict];
            self.pjname = [self objectOrNilForKey:kContentPjname fromDictionary:dict];
            self.firstCategory = [self objectOrNilForKey:kContentFirstCategory fromDictionary:dict];
            self.secondCategory = [self objectOrNilForKey:kContentSecondCategory fromDictionary:dict];
            self.result = [self objectOrNilForKey:kContentResult fromDictionary:dict];
            self.btime = [self objectOrNilForKey:kContentBtime fromDictionary:dict];
            self.content = [self objectOrNilForKey:kContentContent fromDictionary:dict];
            self.institution = [self objectOrNilForKey:kContentInstitution fromDictionary:dict];
            self.finish = [self objectOrNilForKey:kContentFinish fromDictionary:dict];
        
        self.batch = [self objectOrNilForKey:kContentBatch fromDictionary:dict];
        self.testing_date = [self objectOrNilForKey:kContentTesting_date fromDictionary:dict];

    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:self.rank forKey:kContentRank];
    [mutableDict setValue:self.location forKey:kContentLocation];
    [mutableDict setValue:self.institutionid forKey:kContentInstitutionid];
    [mutableDict setValue:self.code forKey:kContentCode];
    [mutableDict setValue:self.mid forKey:kContentMid];
    [mutableDict setValue:self.ctime forKey:kContentCtime];
    [mutableDict setValue:self.brand forKey:kContentBrand];
    [mutableDict setValue:self.emoney forKey:kContentEmoney];
    [mutableDict setValue:self.packageid forKey:kContentPackageid];
    [mutableDict setValue:self.packagename forKey:kContentPackagename];
    [mutableDict setValue:self.pdname forKey:kContentPdname];
    [mutableDict setValue:self.fromtype forKey:kContentFromtype];
    [mutableDict setValue:self.state forKey:kContentState];
    [mutableDict setValue:self.testreportid forKey:kContentTestreportid];
    [mutableDict setValue:self.contentIdentifier forKey:kContentId];
    [mutableDict setValue:self.sample forKey:kContentSample];
    [mutableDict setValue:self.samnum forKey:kContentSamnum];
    [mutableDict setValue:self.etime forKey:kContentEtime];
    [mutableDict setValue:self.thumb forKey:kContentThumb];
    [mutableDict setValue:self.pjname forKey:kContentPjname];
    [mutableDict setValue:self.firstCategory forKey:kContentFirstCategory];
    [mutableDict setValue:self.secondCategory forKey:kContentSecondCategory];
    [mutableDict setValue:self.result forKey:kContentResult];
    [mutableDict setValue:self.btime forKey:kContentBtime];
    [mutableDict setValue:self.content forKey:kContentContent];
    
    [mutableDict setValue:self.batch forKey:kContentBatch];
    [mutableDict setValue:self.testing_date forKey:kContentTesting_date];

    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description 
{
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}


#pragma mark - NSCoding Methods

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super init];

    self.rank = [aDecoder decodeObjectForKey:kContentRank];
    self.location = [aDecoder decodeObjectForKey:kContentLocation];
    self.institutionid = [aDecoder decodeObjectForKey:kContentInstitutionid];
    self.code = [aDecoder decodeObjectForKey:kContentCode];
    self.mid = [aDecoder decodeObjectForKey:kContentMid];
    self.ctime = [aDecoder decodeObjectForKey:kContentCtime];
    self.brand = [aDecoder decodeObjectForKey:kContentBrand];
    self.emoney = [aDecoder decodeObjectForKey:kContentEmoney];
    self.packageid = [aDecoder decodeObjectForKey:kContentPackageid];
    self.pdname = [aDecoder decodeObjectForKey:kContentPdname];
    self.fromtype = [aDecoder decodeObjectForKey:kContentFromtype];
    self.state = [aDecoder decodeObjectForKey:kContentState];
    self.testreportid = [aDecoder decodeObjectForKey:kContentTestreportid];
    self.contentIdentifier = [aDecoder decodeObjectForKey:kContentId];
    self.sample = [aDecoder decodeObjectForKey:kContentSample];
    self.samnum = [aDecoder decodeObjectForKey:kContentSamnum];
    self.etime = [aDecoder decodeObjectForKey:kContentEtime];
    self.thumb = [aDecoder decodeObjectForKey:kContentThumb];
    self.pjname = [aDecoder decodeObjectForKey:kContentPjname];
    self.firstCategory = [aDecoder decodeObjectForKey:kContentFirstCategory];
    self.secondCategory = [aDecoder decodeObjectForKey:kContentSecondCategory];
    self.result = [aDecoder decodeObjectForKey:kContentResult];
    self.btime = [aDecoder decodeObjectForKey:kContentBtime];
    self.content = [aDecoder decodeObjectForKey:kContentContent];
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{

    [aCoder encodeObject:_rank forKey:kContentRank];
    [aCoder encodeObject:_location forKey:kContentLocation];
    [aCoder encodeObject:_institutionid forKey:kContentInstitutionid];
    [aCoder encodeObject:_code forKey:kContentCode];
    [aCoder encodeObject:_mid forKey:kContentMid];
    [aCoder encodeObject:_ctime forKey:kContentCtime];
    [aCoder encodeObject:_brand forKey:kContentBrand];
    [aCoder encodeObject:_emoney forKey:kContentEmoney];
    [aCoder encodeObject:_packageid forKey:kContentPackageid];
    [aCoder encodeObject:_pdname forKey:kContentPdname];
    [aCoder encodeObject:_fromtype forKey:kContentFromtype];
    [aCoder encodeObject:_state forKey:kContentState];
    [aCoder encodeObject:_testreportid forKey:kContentTestreportid];
    [aCoder encodeObject:_contentIdentifier forKey:kContentId];
    [aCoder encodeObject:_sample forKey:kContentSample];
    [aCoder encodeObject:_samnum forKey:kContentSamnum];
    [aCoder encodeObject:_etime forKey:kContentEtime];
    [aCoder encodeObject:_thumb forKey:kContentThumb];
    [aCoder encodeObject:_pjname forKey:kContentPjname];
    [aCoder encodeObject:_firstCategory forKey:kContentFirstCategory];
    [aCoder encodeObject:_secondCategory forKey:kContentSecondCategory];
    [aCoder encodeObject:_result forKey:kContentResult];
    [aCoder encodeObject:_btime forKey:kContentBtime];
    [aCoder encodeObject:_content forKey:kContentContent];
}

- (id)copyWithZone:(NSZone *)zone
{
    ZCMainModel *copy = [[ZCMainModel alloc] init];
    
    if (copy) {

        copy.rank = [self.rank copyWithZone:zone];
        copy.location = [self.location copyWithZone:zone];
        copy.institutionid = [self.institutionid copyWithZone:zone];
        copy.code = [self.code copyWithZone:zone];
        copy.mid = [self.mid copyWithZone:zone];
        copy.ctime = [self.ctime copyWithZone:zone];
        copy.brand = [self.brand copyWithZone:zone];
        copy.emoney = [self.emoney copyWithZone:zone];
        copy.packageid = [self.packageid copyWithZone:zone];
        copy.pdname = [self.pdname copyWithZone:zone];
        copy.fromtype =(id)[self.fromtype copyWithZone:zone];
        copy.state = [self.state copyWithZone:zone];
        copy.testreportid = [self.testreportid copyWithZone:zone];
        copy.contentIdentifier = [self.contentIdentifier copyWithZone:zone];
        copy.sample = [self.sample copyWithZone:zone];
        copy.samnum = [self.samnum copyWithZone:zone];
        copy.etime = [self.etime copyWithZone:zone];
        copy.thumb = [self.thumb copyWithZone:zone];
        copy.pjname = [self.pjname copyWithZone:zone];
        copy.firstCategory = [self.firstCategory copyWithZone:zone];
        copy.secondCategory = [self.secondCategory copyWithZone:zone];
        copy.result = [self.result copyWithZone:zone];
        copy.btime = [self.btime copyWithZone:zone];
        copy.content = [self.content copyWithZone:zone];
    }
    
    return copy;
}


@end
